package com.example.visitedsys.Controller;

import com.example.visitedsys.Shrio.Bean.ResponseBean;
import com.example.visitedsys.informationGet.PageVO;
import com.example.visitedsys.pojo.Order;
import com.example.visitedsys.service.OrderService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;

/**
 * @author  SongPeng
 * @date  2021/11/06 14:21
 * @version 1.0
 */

@RestController
@RequestMapping("/order")
public class OrderController {
    @ModelAttribute
    public void doString(){
        MDC.put("operateModuleName","访客预约模块");
    }
    private static final Logger logger = LogManager.getLogger(OrderController.class);
    /**
     * 添加访客预约*/
    @Autowired
    private OrderService orderService;

    @PostMapping("/add")
    public ResponseBean add(@RequestBody @Validated Order order) {
        logger.info("添加预约");
        orderService.add(order);
        return ResponseBean.success();
    }

    @RequiresPermissions("order:select")
    @GetMapping("/orderList")
    public ResponseBean listData(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize, Order order, @RequestParam Date startTime, @RequestParam  Date endTime){
        logger.info("预约记录表");
        PageVO<Order> orderList=orderService.findOrderList(pageNum,pageSize,order,startTime,endTime);
        return ResponseBean.success(orderList);
    }

    @RequiresPermissions("order:select")
    @GetMapping("/TodayList")
    public ResponseBean TodayData(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize){
        logger.info("当天预约记录表");
        PageVO<Order> orderList=orderService.findTodayList(pageNum,pageSize);
        return ResponseBean.success(orderList);
    }


//    @RequiresPermissions("order:review")
}